package com.gizwits.akka

import java.util.concurrent.TimeUnit

import akka.actor._
import akka.actor.Actor
import  akka.io._
import akka.io.Tcp

import scala.concurrent.{Await, Future}
import scala.concurrent.duration.Duration


class HelloActor extends Actor {


  def receive = {

    case "hello" => println("world")
    case "stop" => context.stop(self)

    case _ => println("huh?")

  }

}

object HelloAkka   {

  def main(args: Array[String]) {
    import  scala.concurrent.ExecutionContext.Implicits.global

    // import akka.actor._
    val system = ActorSystem("HelloSystem")
    // default Actor constructor

    val helloActor = system.actorOf(Props[HelloActor], name = "helloactor")
//    helloActor ! "Hello"
//    helloActor ! "hello"
//    helloActor ! "stop"
//    system.shutdown()
    // helloActor.tell(PoisonPill, ActorRef.noSender)

    ////计划在50ms后将 "Hello"-消息发送给 helloActor
    val interval=Duration(5000, TimeUnit.MILLISECONDS)
   println("-------------------------")
    system.scheduler.scheduleOnce(interval, helloActor, "Hello")
    val  delay = Duration(2, TimeUnit.SECONDS)
    val frequency = Duration(100, TimeUnit.MILLISECONDS)
    system.scheduler.schedule(delay,frequency)({
      helloActor ! "hello"
    })




  }

}
